package ahjava.p11other.gui;
import java.awt.Event;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyEvent;
import javax.swing.JFrame;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.JOptionPane;
import javax.swing.KeyStroke;
public class Swing菜单 extends JFrame {
	private static final long serialVersionUID = 1L;
	// JMenuBar←JMenu←JMenuItem
	Swing菜单() {
		JMenuBar menuBar = new JMenuBar();
		setJMenuBar(menuBar);
		JMenu menu = new JMenu("文件");
		// Alt + F:打开菜单
		// (mnemonic:记忆的)
		menu.setMnemonic('F');
		JMenuItem menuItem = new JMenuItem("保存");
		// ctrl+S触发保存
		// (stroke击球)
		KeyStroke kstr = KeyStroke.getKeyStroke(KeyEvent.VK_S, Event.CTRL_MASK);
		menuItem.setAccelerator(kstr); // Accelerator加速器
		menuItem.setActionCommand("save");
		menuItem.addActionListener(new ActionListener() {
			@Override
			public void actionPerformed(ActionEvent e) {
				String cmd = e.getActionCommand();
				System.out.println(cmd);
				// 弹窗
				JOptionPane.showMessageDialog(null, "Message:" + cmd, "TITLE：消息提示",
						JOptionPane.INFORMATION_MESSAGE);
			}
		});
		menu.add(menuItem);
		menuBar.add(menu);
		setDefaultCloseOperation(EXIT_ON_CLOSE);
		setSize(800, 600);
		setVisible(true);
	}
	public static void main(String[] args) {
		new Swing菜单();
	}
}
